package com.local.videoplayer.activity;

import android.annotation.TargetApi;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.view.WindowManager;
import com.local.videoplayer.R;
import com.local.videoplayer.player.VideoPlayerStandard;
import com.local.videoplayer.utils.SystemBarTintManager;
import java.util.LinkedHashMap;

import static com.local.videoplayer.activity.BaseActivity.PARAM_INTENT;

/**
 * Created by ccx on 17/8/8.
 */

public class VideoPlayActivity extends AppCompatActivity {

    private VideoPlayerStandard videoPlayer;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_video_play);
        hideStatusBar(true);
        Bundle bundle = getIntent().getBundleExtra(PARAM_INTENT);
         videoPlayer =
                (VideoPlayerStandard) findViewById(R.id.videoplayer);
        videoPlayer.setUp(bundle.getString("DATA"), VideoPlayerStandard.SCREEN_WINDOW_FULLSCREEN, bundle
                .getString("NAME"));
        //LinkedHashMap linkedHashMap = new LinkedHashMap();
        //linkedHashMap.put(0,"/storage/emulated/0/Movies/AVRecSample/2017-06-19-16-35-47.mp4");
        //linkedHashMap.put(1,"/storage/emulated/0/DCIM/Camera/VID_20170710_183135.mp4");
        //linkedHashMap.put(2,"/storage/emulated/0/VID_20170810_203330.mp4");
        //videoPlayer.setUp(linkedHashMap,0,VideoPlayerStandard.SCREEN_WINDOW_FULLSCREEN);
        videoPlayer.startVideo();

    }


    @Override
    public void onBackPressed() {
        if (videoPlayer.backPress()) {
            return;
        }
        super.onBackPressed();
    }

    @Override
    protected void onPause() {
        super.onPause();
        videoPlayer.releaseAllVideos();
    }

    /**
     * Apply KitKat specific translucency.
     */
    private void applyKitKatTranslucency() {

        // KitKat translucent navigation/status bar.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setTranslucentStatus(true);
            SystemBarTintManager mTintManager = new SystemBarTintManager(this);
            mTintManager.setStatusBarTintEnabled(true);
            mTintManager.setNavigationBarTintEnabled(true);
            mTintManager.setTintColor(0xFF00beb3);
            Drawable drawable = new ColorDrawable(0xFF00beb3);
            mTintManager.setTintDrawable(drawable);

        }

    }

    @TargetApi(19)
    private void setTranslucentStatus(boolean on) {
        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |= bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }
    public void hideStatusBar(boolean enable) {
        if (enable) {
            WindowManager.LayoutParams lp = getWindow().getAttributes();
            lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
            getWindow().setAttributes(lp);
            //getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        } else {
            //WindowManager.LayoutParams attr = getWindow().getAttributes();
            //attr.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
            //getWindow().setAttributes(attr);
          //  getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        }
    }
}
